home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / bankp.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  7KB  |  283 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *bankp_videoram2;
  15. unsigned char *bankp_colorram2;
  16. static unsigned char *dirtybuffer2;
  17. static struct osd_bitmap *tmpbitmap2;
  18. static int scroll_x;
  19. static int flipscreen;
  20. static int priority;
  21.  
  22.  
  23.  
  24. /***************************************************************************
  25.  
  26.   Convert the color PROMs into a more useable format.
  27.  
  28.   Bank Panic has a 32x8 palette PROM (I'm not sure whether the second 16
  29.   bytes are used - they contain the same colors as the first 16 with only
  30.   one different) and two 256x4 lookup table PROMs (one for charset #1, one
  31.   for charset #2 - only the first 128 nibbles seem to be used).
  32.  
  33.   I don't know for sure how the palette PROM is connected to the RGB output,
  34.   but it's probably the usual:
  35.  
  36.   bit 7 -- 220 ohm resistor  -- BLUE
  37.         -- 470 ohm resistor  -- BLUE
  38.         -- 220 ohm resistor  -- GREEN
  39.         -- 470 ohm resistor  -- GREEN
  40.         -- 1  kohm resistor  -- GREEN
  41.         -- 220 ohm resistor  -- RED
  42.         -- 470 ohm resistor  -- RED
  43.   bit 0 -- 1  kohm resistor  -- RED
  44.  
  45. ***************************************************************************/
  46. void bankp_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  47. {
  48.     int i;
  49.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  50.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  51.  
  52.  
  53.     for (i = 0;i < Machine->drv->total_colors;i++)
  54.     {
  55.         int bit0,bit1,bit2;
  56.  
  57.  
  58.         /* red component */
  59.         bit0 = (*color_prom >> 0) & 0x01;
  60.         bit1 = (*color_prom >> 1) & 0x01;
  61.         bit2 = (*color_prom >> 2) & 0x01;
  62.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  63.         /* green component */
  64.         bit0 = (*color_prom >> 3) & 0x01;
  65.         bit1 = (*color_prom >> 4) & 0x01;
  66.         bit2 = (*color_prom >> 5) & 0x01;
  67.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  68.         /* blue component */
  69.         bit0 = 0;
  70.         bit1 = (*color_prom >> 6) & 0x01;
  71.         bit2 = (*color_prom >> 7) & 0x01;
  72.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  73.  
  74.         color_prom++;
  75.     }
  76.  
  77.     /* color_prom now points to the beginning of the lookup table */
  78.  
  79.     /* charset #1 lookup table */
  80.     for (i = 0;i < TOTAL_COLORS(0);i++)
  81.         COLOR(0,i) = *(color_prom++) & 0x0f;
  82.  
  83.     color_prom += 128;    /* skip the bottom half of the PROM - seems to be not used */
  84.  
  85.     /* charset #2 lookup table */
  86.     for (i = 0;i < TOTAL_COLORS(1);i++)
  87.         COLOR(1,i) = *(color_prom++) & 0x0f;
  88.  
  89.     /* the bottom half of the PROM seems to be not used */
  90. }
  91.  
  92.  
  93.  
  94. /***************************************************************************
  95.  
  96.   Start the video hardware emulation.
  97.  
  98. ***************************************************************************/
  99. int bankp_vh_start(void)
  100. {
  101.     if (generic_vh_start() != 0)
  102.         return 1;
  103.  
  104.     if ((dirtybuffer2 = malloc(videoram_size)) == 0)
  105.     {
  106.         generic_vh_stop();
  107.         return 1;
  108.     }
  109.     memset(dirtybuffer2,1,videoram_size);
  110.  
  111.     if ((tmpbitmap2 = osd_create_bitmap(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  112.     {
  113.         free(dirtybuffer2);
  114.         generic_vh_stop();
  115.         return 1;
  116.     }
  117.  
  118.     return 0;
  119. }
  120.  
  121.  
  122.  
  123. WRITE_HANDLER( bankp_scroll_w )
  124. {
  125.     scroll_x = data;
  126. }
  127.  
  128.  
  129.  
  130. /***************************************************************************
  131.  
  132.   Stop the video hardware emulation.
  133.  
  134. ***************************************************************************/
  135. void bankp_vh_stop(void)
  136. {
  137.     free(dirtybuffer2);
  138.     osd_free_bitmap(tmpbitmap2);
  139.     generic_vh_stop();
  140. }
  141.  
  142.  
  143.  
  144. WRITE_HANDLER( bankp_videoram2_w )
  145. {
  146.     if (bankp_videoram2[offset] != data)
  147.     {
  148.         dirtybuffer2[offset] = 1;
  149.  
  150.         bankp_videoram2[offset] = data;
  151.     }
  152. }
  153.  
  154.  
  155.  
  156. WRITE_HANDLER( bankp_colorram2_w )
  157. {
  158.     if (bankp_colorram2[offset] != data)
  159.     {
  160.         dirtybuffer2[offset] = 1;
  161.  
  162.         bankp_colorram2[offset] = data;
  163.     }
  164. }
  165.  
  166.  
  167.  
  168. WRITE_HANDLER( bankp_out_w )
  169. {
  170.     /* bits 0-1 are playfield priority */
  171.     /* TODO: understand how this works, currently the only thing I do is */
  172.     /* invert the layer order when priority == 2 */
  173.     priority = data & 0x03;
  174.  
  175.     /* bits 2-3 unknown (2 is used) */
  176.  
  177.     /* bit 4 controls NMI */
  178.     if (data & 0x10) interrupt_enable_w(0,1);
  179.     else interrupt_enable_w(0,0);
  180.  
  181.     /* bit 5 controls screen flip */
  182.     if ((data & 0x20) != flipscreen)
  183.     {
  184.         flipscreen = data & 0x20;
  185.         memset(dirtybuffer,1,videoram_size);
  186.         memset(dirtybuffer2,1,videoram_size);
  187.     }
  188.  
  189.     /* bits 6-7 unknown */
  190. }
  191.  
  192.  
  193.  
  194. /***************************************************************************
  195.  
  196.   Draw the game screen in the given osd_bitmap.
  197.   Do NOT call osd_update_display() from this function, it will be called by
  198.   the main emulation engine.
  199.  
  200. ***************************************************************************/
  201. void bankp_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  202. {
  203.     int offs;
  204.  
  205.  
  206.     /* for every character in the Video RAM, check if it has been modified */
  207.     /* since last time and update it accordingly. */
  208.     for (offs = videoram_size - 1;offs >= 0;offs--)
  209.     {
  210.         if (dirtybuffer[offs])
  211.         {
  212.             int sx,sy,flipx;
  213.  
  214.  
  215.             dirtybuffer[offs] = 0;
  216.  
  217.             sx = offs % 32;
  218.             sy = offs / 32;
  219.             flipx = colorram[offs] & 0x04;
  220.             if (flipscreen)
  221.             {
  222.                 sx = 31 - sx;
  223.                 sy = 31 - sy;
  224.                 flipx = !flipx;
  225.             }
  226.  
  227.             drawgfx(tmpbitmap,Machine->gfx[0],
  228.                     videoram[offs] + 256 * ((colorram[offs] & 3) >> 0),
  229.                     colorram[offs] >> 3,
  230.                     flipx,flipscreen,
  231.                     8*sx,8*sy,
  232.                     0,TRANSPARENCY_NONE,0);
  233.         }
  234.  
  235.         if (dirtybuffer2[offs])
  236.         {
  237.             int sx,sy,flipx;
  238.  
  239.  
  240.             dirtybuffer2[offs] = 0;
  241.  
  242.             sx = offs % 32;
  243.             sy = offs / 32;
  244.             flipx = bankp_colorram2[offs] & 0x08;
  245.             if (flipscreen)
  246.             {
  247.                 sx = 31 - sx;
  248.                 sy = 31 - sy;
  249.                 flipx = !flipx;
  250.             }
  251.  
  252.             drawgfx(tmpbitmap2,Machine->gfx[1],
  253.                     bankp_videoram2[offs] + 256 * (bankp_colorram2[offs] & 0x07),
  254.                     bankp_colorram2[offs] >> 4,
  255.                     flipx,flipscreen,
  256.                     8*sx,8*sy,
  257.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  258.         }
  259.     }
  260.  
  261.  
  262.  
  263.  
  264.     /* copy the temporary bitmaps to the screen */
  265.     {
  266.         int scroll;
  267.  
  268.  
  269.         scroll = -scroll_x;
  270.  
  271.         if (priority == 2)
  272.         {
  273.             copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  274.             copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  275.         }
  276.         else
  277.         {
  278.             copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  279.             copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  280.         }
  281.     }
  282. }
  283.